package squelette;

import Lib3d.Vector3d;

public class Spring {

	public static final float VISCOSITY = 7.0f;
	public static final float STIFFNESS = 4.0f;
	
	/**
	 * Calcule la force exercée sur la premiere masse parmi les deux liées au ressort.
	 * @param m1 Masse 1
	 * @param m2 Masse 2
	 * @param initialLength Longueur initiale du ressort.
	 */
	public static Vector3d calculateForce(Mass m1, Mass m2, float initialLength) {
		
		// Obtient la norme du vecteur liant les deux masses du ressort.
		float normForce = Mass.calculateNorm(m1, m2);
		
		float res = STIFFNESS * (1 - (initialLength - normForce));
		Vector3d vRes = Vector3d.sub(m2.getPosition(), m1.getPosition());
		vRes = Vector3d.mul(vRes, res);
		Vector3d vLastTerm = Vector3d.mul(m1.getSpeed(), VISCOSITY);
		
		vRes = Vector3d.sub(vRes, vLastTerm); 
		
		return vRes;
	}
	
	
	
}
